﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FF.Entity;
using System.Data.SQLite;
using System.Data;
using FF.Method;
using System.Windows.Forms;

namespace FF.Method
{
    class CancelOrderMethod
    {
        public static int delete(string id)
        {
            try
            {
                string sql = "delete from ff_cancle_order where cancel_order_id='" + id + "'";
                return SQLiteHelper.ExecuteSql(sql);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 0;
            }

        }

        public static int add(CancelOrder entity)
        {
            string sql = "insert into ff_cancle_order(order_id,customer_id,customer_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,discount,add_date,remark) values('";
            sql += entity.orderId + "','";
            sql += entity.customerId + "','";
            sql += entity.customerName + "','";
            sql += entity.goodId + "','";
            sql += entity.goodName + "','";
            sql += entity.goodNum + "','";
            sql += entity.goodPrice + "','";
            sql += entity.receiverName + "','";
            sql += entity.totalPrices + "','";
            sql += entity.discount + "','";
            //sql += entity.sendDate + "','";
            //sql += entity.sendYear + "','";
            //sql += entity.sendMonth + "','";
            //sql += entity.sendDay + "','";
            sql += entity.addDate + "','";
            //sql += entity.addYear + "','";
            //sql += entity.addMonth + "','";
            //sql += entity.addDay + "','";
            sql += entity.remark + "')";
            try
            {
                return SQLiteHelper.ExecuteSql(sql);
            }
            catch (Exception ex)
            {

                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 0;
            }
        }

        public static int update(CancelOrder entity)
        {
            string sql = "update ff_cancle_order set customer_id='" + entity.customerId + "',";
            sql += "order_id='" + entity.orderId + "',";
            sql += "customer_name='" + entity.customerName + "',";
            sql += "good_id='" + entity.goodId + "',";
            sql += "good_name='" + entity.goodName + "',";
            sql += "good_num='" + entity.goodNum + "',";
            sql += "good_price='" + entity.goodPrice + "',";
            sql += "receiver_name='" + entity.receiverName + "',";
            sql += "total_prices='" + entity.totalPrices + "',";
            sql += "discount='" + entity.discount + "',";

            //sql += "send_date='" + entity.sendDate + "',";
            //sql += "send_year='" + entity.sendYear + "',";
            //sql += "send_month='" + entity.sendMonth + "',";
            //sql += "send_day='" + entity.sendDay + "',";
            sql += "add_date='" + entity.addDate + "',";
            //sql += "add_year='" + entity.addYear + "',";
            //sql += "add_month='" + entity.addMonth + "',";
            //sql += "add_day='" + entity.addDay + "',";
            sql += "remark='" + entity.remark + "' where order_id='" + entity.orderId + "'";
            try
            {
                return SQLiteHelper.ExecuteSql(sql);
            }
            catch (Exception ex)
            {

                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 0;
            }
        }
        public static DataSet queryById(string keyword)
        {
            string sql = "SELECT cancel_order_id,order_id,customer_id,customer_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,discount,strftime('%Y-%m-%d',add_date) as add_date,remark FROM ff_cancle_order where order_id like '%" + keyword + "%'";
            try
            {
                return SQLiteHelper.Query(sql);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }

        public static DataSet queryByGoodId(string keyword)
        {
            string sql = "SELECT cancel_order_id,order_id,customer_id,customer_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,discount,strftime('%Y-%m-%d',add_date) as add_date,remark FROM ff_cancle_order where good_id like '%" + keyword + "%'";
            try
            {
                return SQLiteHelper.Query(sql);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }


        internal static CancelOrder getEntityById(string id)
        {
            CancelOrder order = null;
            try
            {
                SQLiteDataReader reader = SQLiteHelper.ExecuteReader("SELECT order_id,customer_id,customer_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,discount,strftime('%Y-%m-%d',add_date) as add_date,remark, cancel_order_id FROM ff_cancle_order where order_id='" + id + "'");
                if (reader.HasRows)
                {
                    reader.Read();
                    order = new CancelOrder();
                    order.orderId = reader.GetString(0);
                    order.customerId = reader.GetString(1);
                    order.customerName = reader.GetString(2);
                    order.goodId = reader.GetString(3);
                    order.goodName = reader.GetString(4);
                    order.goodNum = reader.GetString(5);//reader.GetInt32(7).ToString();
                    order.goodPrice = reader.GetString(6);
                    order.receiverName = reader.GetString(7);
                    order.totalPrices = reader.GetString(8);
                    order.discount = reader.GetString(9);
                    //order.sendDate = reader.GetString(14);
                    //order.sendYear = reader.GetString(15);
                    //order.sendMonth = reader.GetString(16);
                    //order.sendDay = reader.GetString(17);
                    order.addDate = reader.GetString(10);
                    //order.addYear = reader.GetString(15);
                    //order.addMonth = reader.GetString(16);
                    //order.addDay = reader.GetString(17);
                    order.remark = reader.GetString(11);
                    order.cancelOrderId = reader.GetInt32(12).ToString();
                    //order.inputDate= reader.GetString(23);

                }
                reader.Close();
                return order;
            }
            catch (Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
    }
}
